package com.nhjf.mobile.controller.admin.coursesSeries;


import it.sauronsoftware.jave.Encoder;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.util.WebUtils;

import com.nhjf.command.coursesSeries.CoursesSeriesCommand;
import com.nhjf.common.page.Pagination;
import com.nhjf.mobile.common.util.PictureUtil;
import com.nhjf.mobile.common.util.SysProperties;
import com.nhjf.model.coursePicture.CoursePicture;
import com.nhjf.model.coursesSeries.CoursesSeries;
import com.nhjf.model.system.AdminSession;
import com.nhjf.model.system.Role;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.Courses;
import com.nhjf.model.teachers.CoursesType;
import com.nhjf.model.teachers.OperationLog;
import com.nhjf.model.teachers.Teacher;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.qo.coursePicture.CoursePictureQo;
import com.nhjf.pojo.qo.coursesSeries.CoursesSeriesQo;
import com.nhjf.pojo.qo.system.AdminSessionQo;
import com.nhjf.pojo.qo.system.UserQo;
import com.nhjf.pojo.qo.teachers.CoursesQo;
import com.nhjf.pojo.qo.teachers.CoursesTypeQo;
import com.nhjf.pojo.qo.teachers.TeachersQo;
import com.nhjf.service.coursePicture.CoursePictureService;
import com.nhjf.service.coursesSeries.CoursesSeriesService;
import com.nhjf.service.system.AdminSessionService;
import com.nhjf.service.system.UserService;
import com.nhjf.service.teachers.CoursesService;
import com.nhjf.service.teachers.CoursesTypeService;
import com.nhjf.service.teachers.OperationLogService;
import com.nhjf.service.teachers.TeachersService;

import it.sauronsoftware.jave.MultimediaInfo;
import net.sf.json.JSONObject;

@Controller
@RequestMapping("/coursesSeriesAdmin")
public class CoursesSeriesAdminController {
	@Autowired
	private CoursesSeriesService coursesSeriesService;
	@Autowired
	private TeachersService teacherService;
	@Autowired
	private CoursesTypeService coursesTypeService;
	@Autowired
	private OperationLogService operationLogService;
	@Autowired
	private CoursesService coursesService;
	@Autowired
	private TeachersService teachersService;
	@Autowired
	private UserService userService;
	@Autowired
	private AdminSessionService adminSessionService;
	@Autowired
	private CoursePictureService  coursePictureService;
	/**
	 * 系列课列表
	 * @param request
	 * @param coursesSeriesQo
	 * @param model
	 * @param page
	 * @param token
	 * @return
	 */
	@RequestMapping("/coursesSeries_page")
	@ResponseBody
	public String series_page(@RequestParam(value="isRelease", required=false)Integer isRelease,@RequestParam(value="typeOne", required=false)Integer typeOne,@RequestParam(value="isReview", required=false)Integer isReview,@RequestParam(value="courseStatus", required=false)Integer courseStatus,HttpServletRequest request,  Model model, @RequestParam(value = "page", defaultValue = "1") Integer page,@RequestParam(value="token", required=true) String token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					CoursesSeriesQo coursesSeriesQo= new CoursesSeriesQo();
					if(typeOne!=null) {
						coursesSeriesQo.setCourseTypeOne(typeOne.longValue());
					}
					if(isReview!=null) {
						coursesSeriesQo.setIsReview(isReview);
					}
					if(courseStatus!=null) {
						coursesSeriesQo.setCourseShare(courseStatus);
					}
					if(isRelease!=null) {
						coursesSeriesQo.setIsRelease(isRelease);
					}
					user.setUserPassword("");
					//					if(user.getIsRole()==4) {
					//						coursesSeriesQo.setSeachTeacher(true);
					//						coursesSeriesQo.setIsSeriesLesson(1);
					//						Pagination pagination = new Pagination();
					//						pagination.setPageSize(6);
					//						pagination.setCondition(coursesSeriesQo);
					//						pagination.setPageNo(page);
					//						pagination = coursesSeriesService.queryPagination(pagination);
					//						List<CoursesSeries> coursesList=(List<CoursesSeries>)pagination.getList();
					//						SysProperties sysProperties=SysProperties.getInstance();
					//						String imagePath=sysProperties.get("imagePathAdmin");
					//						for(CoursesSeries courses:coursesList) {
					//							TeachersQo teachersQo=new TeachersQo();
					//							teachersQo.setTeacherId(courses.getUploader().getId());
					//							teachersQo.setSeachUser(true);
					//							Teacher teacher=teacherService.queryUnique(teachersQo);
					//							courses.setUserId(teacher.getUser().getId());
					//							if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
					//								if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
					//								}else {
					//									courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
					//								}
					//							}
					//							courses.setCover(imagePath+"/img/"+courses.getCover());
					//						}
					//						pagination.setList(coursesList);
					//						resMap.put("code", "200");
					//						resMap.put("message", pagination);
					//						return JSONObject.fromObject(resMap).toString();
					//					} else 
					if(user.getIsRole()==1) {
						coursesSeriesQo.setSeachTeacher(true);
						coursesSeriesQo.setIsSeriesLesson(1);
						Pagination pagination = new Pagination();
						pagination.setPageSize(16);
						TeachersQo teachersQo=new  TeachersQo();
						teachersQo.setUserId(user.getId());
						Teacher teacher= teacherService.queryUnique(teachersQo);
						coursesSeriesQo.setUploader(teacher.getId());
						pagination.setCondition(coursesSeriesQo);
						pagination.setPageNo(page);
						pagination = coursesSeriesService.queryPagination(pagination);
						List<CoursesSeries> coursesList=(List<CoursesSeries>)pagination.getList();
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						for(CoursesSeries courses:coursesList) {
							TeachersQo teachersQo1=new TeachersQo();
							teachersQo1.setTeacherId(courses.getUploader().getId());
							teachersQo1.setSeachUser(true);
							Teacher teacher1=teacherService.queryUnique(teachersQo1);
							courses.setUserId(teacher1.getUser().getId());
							if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
								if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
								}else {
									courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
								}
							}
							courses.setCover(imagePath+"/img/"+courses.getCover());
						}
						pagination.setList(coursesList);
						resMap.put("code", "200");
						resMap.put("message", pagination);
						return JSONObject.fromObject(resMap).toString();
					}else if(user.getIsRole()==3) {
						coursesSeriesQo.setSeachTeacher(true);
						coursesSeriesQo.setIsSeriesLesson(1);
						Pagination pagination = new Pagination();
						pagination.setPageSize(16);
						TeachersQo teachersQo=new  TeachersQo();
						teachersQo.setUserId(user.getId());
						teachersQo.setSeachOrganization(true);
						Teacher teacher= teacherService.queryUnique(teachersQo);
						coursesSeriesQo.setOrganizationId(teacher.getTraininginstitution().getId());
						coursesSeriesQo.setIsSeriesLesson(1);
						pagination.setCondition(coursesSeriesQo);
						pagination.setPageNo(page);
						pagination = coursesSeriesService.queryPagination(pagination);

						List<CoursesSeries> coursesList=(List<CoursesSeries>)pagination.getList();
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						for(CoursesSeries courses:coursesList) {
							TeachersQo teachersQo1=new TeachersQo();
							teachersQo1.setTeacherId(courses.getUploader().getId());
							teachersQo1.setSeachUser(true);
							Teacher teacher1=teacherService.queryUnique(teachersQo1);
							courses.setUserId(teacher1.getUser().getId());
							if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
								if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
								}else {
									courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
								}
							}
							courses.setCover(imagePath+"/img/"+courses.getCover());
						}
						pagination.setList(coursesList);
						resMap.put("code", "200");
						resMap.put("message", pagination);
						return JSONObject.fromObject(resMap).toString();
					}
				}else {
					resMap.put("code", "406");
					resMap.put("message", "请先登录!");
					return net.sf.json.JSONObject.fromObject(resMap).toString();
				}
			}
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		}
	}

	/**
	 * 根据id查看系列课
	 * @param model
	 * @return
	 */
	@RequestMapping("/coursesSeries_seriesLesson")
	@ResponseBody
	public String coursesSeries_seriesLesson(Model model,String id, @RequestParam(value = "page", defaultValue = "1") Integer page,@RequestParam(value="token", required=true) String token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					CoursesQo coursesQo=new CoursesQo();
					coursesQo.setSeachCoursesSeries(true);
					coursesQo.setSeachUploader(true);
					coursesQo.setTimeSort(false);
					coursesQo.setSeriesId(Long.parseLong(id));
					List<Courses> coursesList = coursesService.queryList(coursesQo);
					SysProperties sysProperties=SysProperties.getInstance();
					String imagePath=sysProperties.get("imagePath");
					CoursesSeries coursesSeries=coursesSeriesService.get(Long.parseLong(id));
					coursesSeries.setCoursesList(coursesList);
					CoursePictureQo qo=new CoursePictureQo();
					qo.setSeachCoursesSeries(true);
					qo.setCoursesSeriesId(coursesSeries.getId());
					List<CoursePicture> picturesList= coursePictureService.queryList(qo);
					for (CoursePicture coursePicture : picturesList) {
						if(StringUtils.isNotBlank(coursePicture.getImageUrl())) {
							coursePicture.setImageUrl(imagePath+"/map/"+coursePicture.getImageUrl());
						}
						
					}
					coursesSeries.setCoursePictureList(picturesList);
					for(Courses courses:coursesList) {
						TeachersQo teachersQo1=new TeachersQo();
						teachersQo1.setTeacherId(courses.getUploader().getId());
						teachersQo1.setSeachUser(true);
						Teacher teacher1=teacherService.queryUnique(teachersQo1);
						courses.setUserId(teacher1.getUser().getId());
						if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
							if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
							}else {
								courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
							}
						}
						if(StringUtils.isNotEmpty(courses.getVideo())) {
							if(courses.getVideo().indexOf(imagePath+"/videofile/")>=0) {
							}else {
								courses.setVideo(imagePath+"/videofile/"+courses.getVideo());
							}
						}

					}
					if(StringUtils.isNotEmpty(coursesSeries.getCover())) {
						if(coursesSeries.getCover().indexOf(imagePath+"/img/")>=0) {
						}else {
							coursesSeries.setCover(imagePath+"/img/"+coursesSeries.getCover());
						}
					}
					resMap.put("code", "200");
					resMap.put("message", coursesSeries);
					return JSONObject.fromObject(resMap).toString();
				}else {
					resMap.put("code", "406");
					resMap.put("message", "请先登录!");
					return net.sf.json.JSONObject.fromObject(resMap).toString();
				}
			}
			resMap.put("code", "500");
			resMap.put("message", "异常抛出!");
			return net.sf.json.JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "异常抛出!");
			return net.sf.json.JSONObject.fromObject(resMap).toString();
		}

	}
	/**
	 * 跳转系列课添加页面
	 * @param model
	 * @return
	 */
	@RequestMapping("/coursesSeries_add")
	@ResponseBody
	public String tz_coursesSeriesadd(Model model) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		CoursesTypeQo coursesTypeQo=new CoursesTypeQo();
		coursesTypeQo.setType(1);
		List<CoursesType> coursesType =coursesTypeService.queryList(coursesTypeQo);
		model.addAttribute("coursesType",coursesType);
		resMap.put("code", "200");
		resMap.put("message", coursesType);
		return JSONObject.fromObject(resMap).toString();
	}
	//系列课创建
	@ResponseBody
	@RequestMapping(value= "/courseSeries_adds")
	public String save(@RequestParam("pic")MultipartFile pic,@RequestParam("files")MultipartFile[] files,HttpServletRequest request,HttpServletResponse response,CoursesSeriesQo qo,@RequestParam(value="token", required=true) String token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				qo.setPrice(null);
				if(user!=null) {
					user.setUserPassword("");
					if(user.getIsRole()==4) {
						resMap.put("code", "505");
						resMap.put("message", "最高管理员不能操作!");
						return JSONObject.fromObject(resMap).toString();
					} else if(user.getIsRole()==3 || user.getIsRole()==1) {
						if (pic.isEmpty()) {
							resMap.put("code", "500");
							resMap.put("message", "上传图片不可为空");
							return JSONObject.fromObject(resMap).toString();
						}
						int returnTag = -1;
						SysProperties sysProperties=SysProperties.getInstance();
						String imgPath=sysProperties.get("imagePathAdmin");
						//获取图片原始文件名
						String originalFilename = pic.getOriginalFilename();
						System.out.println(originalFilename);
						//文件名使用当前时间
						String name = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
						// 获取上传图片的扩展名(jpg/png/...)
						String extension = FilenameUtils.getExtension(originalFilename);
						String[] regular = { "JPG", "GIF","PNG","JPEG" ,"BMP"};
						boolean flag = false;
						// 判断文件格式是否合法
						for (String str : regular) {
							if (extension.equalsIgnoreCase(str)) {
								flag = true;
							}
						}
						if (!flag) {
							returnTag = 0;
							resMap.put("code", "500");
							resMap.put("message", "上传图片格式不正确！");
							return JSONObject.fromObject(resMap).toString();
						}
						// 图片上传的相对路径（因为相对路径放到页面上就可以显示图片）
						String path =imgPath + name + "." + extension;
						//图片上传的绝对路径

						File dir = new File(path);
						if (!dir.exists()) {
							dir.mkdirs();
						}
						// 上传图片
						pic.transferTo(new File(path));

						//保存课程信息
						TeachersQo teachersQo=new TeachersQo();
						teachersQo.setUserId(user.getId());
						Teacher teacher=teacherService.queryUnique(teachersQo);
						if(teacher==null) {
							resMap.put("code", "500");
							resMap.put("message", "上传图片格式不正确！");
							return JSONObject.fromObject(resMap).toString();
						}
						List<String> strlist=new ArrayList<String>();
						String dateString= new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
						for (int i=1 ;i<=files.length;i++ ) {
							int returnTags = -1;
							SysProperties sysPropertiess=SysProperties.getInstance();

							String courseMap=sysPropertiess.get("courseMap");
							//获取图片原始文件名
							String finetTalk = files[i-1].getOriginalFilename();
							System.out.println(finetTalk);
							//文件名使用当前时间
							String names = dateString+"-"+i;
							// 获取上传图片的扩展名(jpg/png/...)
							String extensions = FilenameUtils.getExtension(finetTalk);
							String[] regulars = { "JPG", "GIF","PNG","JPEG" ,"BMP"};
							boolean flags = false;
							// 判断文件格式是否合法
							for (String str : regulars) {
								if (extensions.equalsIgnoreCase(str)) {
									flags = true;
								}
							}
							if (!flag) {
								returnTags = 0;
								resMap.put("code", "500");
								resMap.put("message", "上传图片格式不正确！");
								return JSONObject.fromObject(resMap).toString();
							}
							// 图片上传的相对路径（因为相对路径放到页面上就可以显示图片）
							String paths =courseMap+"/"+user.getId() +"/" +names + "." + extension;
							strlist.add(user.getId() +"/" +names + "." + extension);
							//图片上传的绝对路径

							File dirs = new File(paths);
							if (!dirs.exists()) {
								dirs.mkdirs();
							}
							// 上传图片
							files[i-1].transferTo(new File(paths));
						}
						qo.setImgList(strlist);
						qo.setUploader(teacher.getId());
						qo.setSeachTeacher(true);
						qo.setCover(name + "." + extension);
						java.util.Date  date=new java.util.Date();
						qo.setCreationTime(date);
						qo.setIsReview(0);
						qo.setIsTopping(2);
						qo.setIsSeriesLesson(1);
						ServiceResultDto serviceResultDto=coursesSeriesService.findadd(qo);
						if(serviceResultDto.getSuccess()) {
							OperationLog operationLog=new OperationLog();
							operationLog.setOperationType(2);
							operationLog.setOperationDescription("系列课课添加!");
							operationLog.setUserId(user);
							operationLog.setOperationTime(new Date());
							operationLog.setOperationUserName(user.getUserName());
							operationLogService.save(operationLog);
							resMap.put("code", "200");
							resMap.put("message", ((CoursesSeries)serviceResultDto.getUniqueResult()).getId());
							return JSONObject.fromObject(resMap).toString();
						}
					}
				}else {
					resMap.put("code", "406");
					resMap.put("message", "请先登录!");
					return net.sf.json.JSONObject.fromObject(resMap).toString();
				}

			}
			resMap.put("code", "500");
			resMap.put("message", "操作错误！");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 分类查询
	 * @param request
	 * @param response
	 * @param model
	 * @param typeOne
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/coursesType_Subctype")
	public String showSubctype(HttpServletRequest request, HttpServletResponse response, Model model,String typeOne) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			CoursesTypeQo coursesTypeQo=new CoursesTypeQo();
			coursesTypeQo.setpId(Long.parseLong(typeOne));
			coursesTypeQo.setType(2);
			List<CoursesType> list=coursesTypeService.queryList(coursesTypeQo);
			if(list!=null) {
				resMap.put("code", "200");
				resMap.put("message", list);
				return JSONObject.fromObject(resMap).toString();
			}else {
				resMap.put("code", "404");
				resMap.put("message", "没有找到分类！");
				return JSONObject.fromObject(resMap).toString();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 跳转审核
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping("/series_tzReview")
	@ResponseBody
	public String series_tzReview(String id,Model model) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		CoursesSeriesQo coursesSeriesQo=new CoursesSeriesQo();
		coursesSeriesQo.setCoursesSeriesId(Long.parseLong(id));
		CoursesSeries coursesSeries=coursesSeriesService.queryUnique(coursesSeriesQo);
		CoursesQo coursesQo=new CoursesQo();
		coursesQo.setSeachCoursesSeries(true);
		coursesQo.setSeriesId(coursesSeries.getId());
		coursesQo.setIsReview(0);
		List<Courses> courses=coursesService.queryList(coursesQo);
		if(coursesSeries.getIsReview()==1 && courses.size()<1) {
			resMap.put("code", "500");
			resMap.put("message", "重复操作!已经审核!");
			return JSONObject.fromObject(resMap).toString();
		}
		if(coursesSeries.getIsPrice()==2 && coursesSeries.getPrice()==null) {
			model.addAttribute("shoufei",2);//IsPrice()==2 收费
		}
		resMap.put("code", "200");
		resMap.put("message", coursesSeries);
		return JSONObject.fromObject(resMap).toString();
	}
	/**
	 * 系列课审核
	 * @param request
	 * @param session
	 * @param response
	 * @param id
	 * @param price
	 * @param token
	 * @return
	 */
	@RequestMapping("/series_review")
	@ResponseBody
	public String series_Review(HttpServletRequest request,HttpSession session,HttpServletResponse response,String id,String price,@RequestParam(value="token", required=true) String token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					user.setUserPassword("");
					if(id==null && id=="") {
						resMap.put("code", "500");
						resMap.put("message", "没有找到系列课!");
						return JSONObject.fromObject(resMap).toString();
					}else{
						CoursesSeriesQo coursesSeriesQo=new CoursesSeriesQo();
						coursesSeriesQo.setSeachTeacher(true);
						coursesSeriesQo.setCoursesSeriesId(Long.parseLong(id));
						CoursesSeries cs=coursesSeriesService.queryUnique(coursesSeriesQo);
						CoursesQo coursesQo=new CoursesQo();
						coursesQo.setSeachCoursesSeries(true);
						coursesQo.setSeachUploader(true);
						coursesQo.setSeriesId(cs.getId());
						coursesQo.setIsReview(0);
						Courses courses=coursesService.queryUnique(coursesQo);
						if(courses!=null) {
							courses.setIsReview(1);
							coursesService.update(courses);
						}
						if(cs.getIsReview()==0 && cs.getIsPrice()==2) {
							cs.setPrice(Integer.parseInt(price));
							cs.setIsReview(1);
							coursesSeriesService.update(cs);
							resMap.put("code", "200");
							resMap.put("message", "成功!");
							return JSONObject.fromObject(resMap).toString();
						}else {
							cs.setIsReview(1);
							coursesSeriesService.update(cs);
							resMap.put("code", "200");
							resMap.put("message", "成功!");
							return JSONObject.fromObject(resMap).toString();
						}

					}
				}else {
					resMap.put("code", "406");
					resMap.put("message", "请先登录!");
					return net.sf.json.JSONObject.fromObject(resMap).toString();
				}
			}
			resMap.put("code", "500");
			resMap.put("message", "操作异常!");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 置顶审核
	 * @param request
	 * @param session
	 * @param response
	 * @param id
	 * @param token
	 * @return
	 */
	@RequestMapping("/series_topping")
	@ResponseBody
	public String series_Topping(HttpServletRequest request,HttpSession session,HttpServletResponse response,String id,@RequestParam(value="token", required=true) String token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					user.setUserPassword("");
					if(id==null && id=="") {
						resMap.put("code", "500");
						resMap.put("message", "没有找到!");
						return JSONObject.fromObject(resMap).toString();
					}else{
						CoursesSeriesQo coursesSeriesQo=new CoursesSeriesQo();
						coursesSeriesQo.setSeachTeacher(true);
						coursesSeriesQo.setCoursesSeriesId(Long.parseLong(id));
						CoursesSeries cs=coursesSeriesService.queryUnique(coursesSeriesQo);
						if(cs.getIsTopping()==2) {
							cs.setIsTopping(1);
							coursesSeriesService.update(cs);
							resMap.put("code", "200");
							resMap.put("message", "通过!");
							return JSONObject.fromObject(resMap).toString();
						}else if(cs.getIsReview()==1) {
							cs.setIsTopping(2);
							coursesSeriesService.update(cs);
							resMap.put("code", "200");
							resMap.put("message", "通过!");
							return JSONObject.fromObject(resMap).toString();
						}
						else {
							resMap.put("code", "500");
							resMap.put("message", "操作异常!");
							return JSONObject.fromObject(resMap).toString();
						}

					}
				}else {
					resMap.put("code", "406");
					resMap.put("message", "请先登录!");
					return net.sf.json.JSONObject.fromObject(resMap).toString();
				}
			}
			resMap.put("code", "500");
			resMap.put("message", "操作异常!");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 删除系列课
	 * @param request
	 * @param session
	 * @param response
	 * @param id
	 * @return
	 */
//	@RequestMapping("/series_delete")
//	@ResponseBody
//	public String series_Delete(HttpServletRequest request,HttpSession session,HttpServletResponse response,String id,@RequestParam(value="token", required=true) String token) {
//		Map<String, Object> resMap=new HashMap<String, Object>();
//		try {
//			AdminSessionQo adminSessionQo=new AdminSessionQo();
//			adminSessionQo.setToken(token);
//			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
//			if(adminSession!=null) {
//				UserQo userQo=new UserQo();
//				userQo.setUserName(adminSession.getLoginName());
//				User user= userService.queryUnique(userQo);
//				if(user!=null) {
//					user.setUserPassword("");
//					if(user.getIsRole()==4) {
//						resMap.put("code", "500");
//						resMap.put("message", "最高管理员不能操作!");
//						return JSONObject.fromObject(resMap).toString();
//					}
//					if(id==null && id=="") {
//						resMap.put("code", "500");
//						resMap.put("message", "没有找到!");
//						return JSONObject.fromObject(resMap).toString();
//					}else{
//						CoursesQo coursesQo=new CoursesQo();
//						coursesQo.setSeachCoursesSeries(true);
//						coursesQo.setSeachUploader(true);
//						CoursesSeriesQo coursesSeriesQo=new CoursesSeriesQo();
//						coursesSeriesQo.setSeachTeacher(true);
//						coursesSeriesQo.setCoursesSeriesId(Long.parseLong(id));
//						CoursesSeries coursesSeries=coursesSeriesService.queryUnique(coursesSeriesQo);
//						TeachersQo teachersQo=new TeachersQo();
//						teachersQo.setSeachOrganization(true);
//						teachersQo.setSeachUser(true);
//						teachersQo.setTeacherId(coursesSeries.getUploader().getId());
//						Teacher teacher=teachersService.queryUnique(teachersQo);
//						teacher.setCoursesNum(teacher.getCoursesNum()-1);
//						teachersService.update(teacher);
//						coursesQo.setSeriesId(coursesSeries.getId());
//						Courses cs= coursesService.queryUnique(coursesQo);
//						SysProperties sysProperties=SysProperties.getInstance();
//						String imgPath=sysProperties.get("imagePathAdmin");
//						File dest = new File(imgPath+coursesSeries.getCover());
//						// 路径为文件且不为空则进行删除  
//						if (dest.isFile() && dest.exists()) {  
//							dest.delete();  
//						}
//						String videoPath=sysProperties.get("fileUploadPath");
//						File dest2 = new File(videoPath+cs.getVideo());
//						if(dest2.isFile() && dest2.exists()) {
//							dest2.delete();
//						}
//						coursesService.deleteById(cs.getId());
//						coursesSeriesService.deleteById(Long.parseLong(id));
//						OperationLog operationLog=new OperationLog();
//						operationLog.setOperationType(1);
//						operationLog.setOperationDescription("系列课删除!");
//						operationLog.setUserId(user);
//						operationLog.setOperationTime(new Date());
//						operationLog.setOperationUserName(user.getUserName());
//						operationLogService.save(operationLog);
//						resMap.put("code", "200");
//						resMap.put("message", "成功!");
//						return JSONObject.fromObject(resMap).toString();
//					}
//				}else {
//					resMap.put("code", "406");
//					resMap.put("message", "请先登录!");
//					return net.sf.json.JSONObject.fromObject(resMap).toString();
//				}
//			}
//			resMap.put("code", "500");
//			resMap.put("message", "操作异常!");
//			return JSONObject.fromObject(resMap).toString();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//			resMap.put("code", "500");
//			resMap.put("message", "系统异常!");
//			return JSONObject.fromObject(resMap).toString();
//		}
//	}
	/**
	 * 跳转课程上传页面
	 * @param model
	 * @return
	 */
	@RequestMapping("/newCourses")
	@ResponseBody
	public String tznewCourses(Model model) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		CoursesTypeQo coursesTypeQo=new CoursesTypeQo();
		coursesTypeQo.setType(1);
		List<CoursesType> coursesType =coursesTypeService.queryList(coursesTypeQo);
		if(coursesType==null) {
			resMap.put("code", "500");
			resMap.put("message", "没有找到类型!");
			return JSONObject.fromObject(resMap).toString();
		}else {
			resMap.put("code", "200");
			resMap.put("message", coursesType);
			return JSONObject.fromObject(resMap).toString();
		}

	}
	/**
	 * 跳转系列课修改页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping("/modify_toSeries")
	@ResponseBody
	public String modify_toSeries(String id,Model model) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		CoursesQo coursesQo=new CoursesQo();
		coursesQo.setSeachCoursesSeries(true);
		coursesQo.setSeachUploader(true);
		coursesQo.setCoursesId(Long.parseLong(id));
		Courses courses=coursesService.queryUnique(coursesQo);
		CoursesTypeQo coursesTypeQo=new CoursesTypeQo();
		coursesTypeQo.setType(1);
		List<CoursesType> coursesType =coursesTypeService.queryList(coursesTypeQo);
		SysProperties sysProperties=SysProperties.getInstance();
		String imagePath=sysProperties.get("imagePath");
		resMap.put("coursesType", coursesType);
		resMap.put("courses", courses);
		resMap.put("code", "200");
		resMap.put("imagePath", imagePath);
		return JSONObject.fromObject(resMap).toString();
	}
	/**
	 * 修改系列课
	 * @param request
	 * @param response
	 * @param model
	 * @param fileName
	 * @param command
	 * @param page
	 * @param token
	 * @return
	 */

	@ResponseBody
	@RequestMapping(value= "/courseSeries_update")
	public String update(HttpServletRequest request, HttpServletResponse response, Model model,String fileName,CoursesSeriesCommand command, @RequestParam(value = "page", defaultValue = "1") Integer page,@RequestParam(value="token", required=true) String token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					user.setUserPassword("");
					if(user.getIsRole()==4) {
						resMap.put("code", "500");
						resMap.put("message", "最高管理员不能操作！");
						return JSONObject.fromObject(resMap).toString();
					}
					SysProperties sysProperties1=SysProperties.getInstance();
					String fileTemPath=sysProperties1.get("temporaryFileUploadPath");
					String filePath=sysProperties1.get("fileUploadPath");
					SysProperties sysProperties=SysProperties.getInstance();
					String imgPath=sysProperties.get("imagePathAdmin");
					if ( user== null) {
						// 跳转到登录页面
						response.sendRedirect(request.getContextPath()+"/login");
					}
					if(command.getCoursesId()==null) {
						resMap.put("code", "404");
						resMap.put("message", "没有此账号！");
						return JSONObject.fromObject(resMap).toString();
					}
					CoursesQo coursesQo=new CoursesQo();
					coursesQo.setCoursesId(command.getCoursesId());
					Courses courses=coursesService.queryUnique(coursesQo);
					MultipartFile pic = null;
					boolean isMultipart = ServletFileUpload.isMultipartContent(request);
					if (isMultipart){ 
						MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
						pic = multipartRequest.getFile("pic");
						if(pic==null) {
							if(StringUtils.isNotBlank(fileName)) {
								PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
								File source = new File(filePath+user.getId()+"/"+fileName);
								Encoder encoder = new Encoder();
								String length = "";
								MultimediaInfo m = encoder.getInfo(source);
								System.out.println("-------"+m.getDuration());
								long ls = m.getDuration()/1000;
								int hour = (int) (ls/3600);
								int minute = (int) (ls/60);
								int second = (int) (ls-hour*3600-minute*60);
								length = minute+":"+second;
								command.setViewTime(length);
								command.setVideo(user.getId()+"/"+fileName);
								String delfile=filePath+courses.getVideo();
								File delvidel = new File(delfile);
								// 路径为文件且不为空则进行删除  
								if (delvidel.isFile() && delvidel.exists()) {  
									delvidel.delete();  
								}
								PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
							}
							ServiceResultDto ts= coursesService.mudifyCommand(command);
							if(ts.getSuccess()) {
								OperationLog operationLog=new OperationLog();
								operationLog.setOperationType(3);
								operationLog.setOperationDescription("系列课修改!");
								operationLog.setUserId(user);
								operationLog.setOperationTime(new Date());
								operationLog.setOperationUserName(user.getUserName());
								operationLogService.save(operationLog);
								resMap.put("code", "200");
								resMap.put("message", "成功!");
								return JSONObject.fromObject(resMap).toString();
							}
						}else {


							String imge =imgPath+courses.getCoursesSeries().getCover();
							File dest = new File(imge);
							// 路径为文件且不为空则进行删除  
							if (dest.isFile() && dest.exists()) {  
								dest.delete();  
							}
							if (pic.isEmpty()) {
								resMap.put("code", "500");
								resMap.put("message", "上传图片不可为空");
								return JSONObject.fromObject(resMap).toString();
							}
							int returnTag = -1;

							// 获取图片原始文件名
							String originalFilename = pic.getOriginalFilename();
							System.out.println(originalFilename);
							//文件名使用当前时间
							String name = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
							// 获取上传图片的扩展名(jpg/png/...)
							String extension = FilenameUtils.getExtension(originalFilename);
							String[] regular = { "JPG", "GIF","PNG","JPEG" ,"BMP"};
							boolean flag1 = false;
							// 判断文件格式是否合法
							for (String str : regular) {
								if (extension.equalsIgnoreCase(str)) {
									flag1 = true;
								}
							}
							if (!flag1) {
								returnTag = 0;
								resMap.put("code", "500");
								resMap.put("message", "上传图片格式不正确！");
								return JSONObject.fromObject(resMap).toString();
							}
							// 图片上传的相对路径（因为相对路径放到页面上就可以显示图片）
							String path =imgPath + name + "." + extension;
							//图片上传的绝对路径
							File dir = new File(path);
							if (!dir.exists()) {
								dir.mkdirs();
							}
							// 上传图片
							pic.transferTo(new File(path));
							if(StringUtils.isNotBlank(fileName)) {
								command.setVideo(user.getId()+"/"+fileName);
								String delfile=filePath+courses.getVideo();
								File delvidel = new File(delfile);
								// 路径为文件且不为空则进行删除  
								if (delvidel.isFile() && delvidel.exists()) {  
									delvidel.delete();  
								}
								PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
							}
							PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
							File source = new File(filePath+user.getId()+"/"+fileName);
							Encoder encoder = new Encoder();
							String length = "";
							MultimediaInfo m = encoder.getInfo(source);
							System.out.println("-------"+m.getDuration());
							long ls = m.getDuration()/1000;
							int hour = (int) (ls/3600);
							int minute = (int) (ls/60);
							int second = (int) (ls-hour*3600-minute*60);
							length = minute+":"+second;
							command.setViewTime(length);
							command.setCover(name + "." + extension);
							ServiceResultDto ts= coursesService.mudifyCommand(command);
							if(ts.getSuccess()) {
								OperationLog operationLog=new OperationLog();
								operationLog.setOperationType(3);
								operationLog.setOperationDescription("系列课课修改!");
								operationLog.setUserId(user);
								operationLog.setOperationTime(new Date());
								operationLog.setOperationUserName(user.getUserName());
								operationLogService.save(operationLog);
								resMap.put("code", "200");
								resMap.put("message", "成功!");
								return JSONObject.fromObject(resMap).toString();
							}
						}
					}else {
						if(StringUtils.isNotBlank(fileName)) {
							command.setVideo(user.getId()+"/"+fileName);
							String delfile=filePath+courses.getVideo();
							File delvidel = new File(delfile);
							// 路径为文件且不为空则进行删除  
							if (delvidel.isFile() && delvidel.exists()) {  
								delvidel.delete();  
							}
							PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
						}
						ServiceResultDto ts=coursesService.mudifyCommand(command);
					}

				}else {
					resMap.put("code", "406");
					resMap.put("message", "请先登录!");
					return net.sf.json.JSONObject.fromObject(resMap).toString();
				}
			}

		} catch (Exception e) {
			// TODO: handle exception
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		}
		resMap.put("code", "500");
		resMap.put("message", "操作异常!");
		return JSONObject.fromObject(resMap).toString();
	}
	//去系列课修改页面
	@RequestMapping("/tz_update")
	@ResponseBody
	public String tz_update(String id,Model model) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		CoursesTypeQo coursesTypeQo=new CoursesTypeQo();
		coursesTypeQo.setType(1);
		List<CoursesType> coursesType =coursesTypeService.queryList(coursesTypeQo);
		resMap.put("coursesType", coursesType);
		CoursesSeriesQo seriesQo=new CoursesSeriesQo();
		seriesQo.setCoursesSeriesId(Long.parseLong(id));
		seriesQo.setSeachTeacher(true);
		CoursesSeries coursesSeries=coursesSeriesService.queryUnique(seriesQo);
		if(null!=coursesSeries ) {
			SysProperties sysProperties=SysProperties.getInstance();
			String imagePath=sysProperties.get("imagePath");
			resMap.put("coursesSeries", coursesSeries);
			resMap.put("imagePath", imagePath);
		}
		resMap.put("code", "200");
		return JSONObject.fromObject(resMap).toString();
	}
	//课程修改course_update
	@ResponseBody
	@RequestMapping(value= "/courseSeries_update1")
	public String update1(HttpServletRequest request, HttpServletResponse response, Model model,CoursesSeriesQo q,@RequestParam(value="token", required=true) String token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					user.setUserPassword("");
					if(user.getIsRole()==4) {
						SysProperties sysProperties1=SysProperties.getInstance();
						//					String fileTemPath=sysProperties1.get("temporaryFileUploadPath");
						//					String filePath=sysProperties1.get("fileUploadPath");
						SysProperties sysProperties=SysProperties.getInstance();
						String imgPath=sysProperties.get("imagePathAdmin");
						if ( user== null) {
							// 跳转到登录页面
							response.sendRedirect(request.getContextPath()+"/login");
						}
						q.setPrice(null);
						if(q.getCoursesSeriesId()==null) {
							resMap.put("code", "404");
							resMap.put("message", "没有此账号！");
							return JSONObject.fromObject(resMap).toString();
						}
						CoursesSeriesQo coursesSeriesQo=new CoursesSeriesQo();
						coursesSeriesQo.setCoursesSeriesId(q.getCoursesSeriesId());
						CoursesSeries series=coursesSeriesService.queryUnique(coursesSeriesQo);
						MultipartFile pic = null;
						boolean isMultipart = ServletFileUpload.isMultipartContent(request);
						if (isMultipart){ 
							MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
							pic = multipartRequest.getFile("pic");
							if(pic==null) {
								//							if(StringUtils.isNotBlank(fileName)) {
								//								PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
								//								File source = new File(filePath+user.getId()+"/"+fileName);
								//								Encoder encoder = new Encoder();
								//								String length = "";
								//								MultimediaInfo m = encoder.getInfo(source);
								//								System.out.println("-------"+m.getDuration());
								//								long ls = m.getDuration()/1000;
								//								int hour = (int) (ls/3600);
								//								int minute = (int) (ls/60);
								//								int second = (int) (ls-hour*3600-minute*60);
								//								length = minute+":"+second;
								//								q.setViewTime(length);
								//								q.setVideo(user.getId()+"/"+fileName);
								//								String delfile=filePath+courses.getVideo();
								//								File delvidel = new File(delfile);
								//								// 路径为文件且不为空则进行删除  
								//								if (delvidel.isFile() && delvidel.exists()) {  
								//									delvidel.delete();  
								//								}
								//								PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
								//							}
								ServiceResultDto ts= coursesSeriesService.findpmodify(q);
								if(ts.getSuccess()) {
									OperationLog operationLog=new OperationLog();
									operationLog.setOperationType(3);
									operationLog.setOperationDescription("课程修改!");
									operationLog.setUserId(user);
									operationLog.setOperationTime(new Date());
									operationLog.setOperationUserName(user.getUserName());
									operationLogService.save(operationLog);
									resMap.put("code", "200");
									resMap.put("message","成功!");
									return JSONObject.fromObject(resMap).toString();
								}
							}else {


								String imge =imgPath+series.getCover();
								File dest = new File(imge);
								// 路径为文件且不为空则进行删除  
								if (dest.isFile() && dest.exists()) {  
									dest.delete();  
								}
								if (pic.isEmpty()) {
									resMap.put("code", "500");
									resMap.put("message", "上传图片不可为空");
									return JSONObject.fromObject(resMap).toString();
								}
								int returnTag = -1;

								// 获取图片原始文件名
								String originalFilename = pic.getOriginalFilename();
								System.out.println(originalFilename);
								//文件名使用当前时间
								String name = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
								// 获取上传图片的扩展名(jpg/png/...)
								String extension = FilenameUtils.getExtension(originalFilename);
								String[] regular = { "JPG", "GIF","PNG","JPEG" ,"BMP"};
								boolean flag1 = false;
								// 判断文件格式是否合法
								for (String str : regular) {
									if (extension.equalsIgnoreCase(str)) {
										flag1 = true;
									}
								}
								if (!flag1) {
									returnTag = 0;
									resMap.put("code", "500");
									resMap.put("message", "上传图片格式不正确！");
									return JSONObject.fromObject(resMap).toString();
								}
								//图片上传的相对路径（因为相对路径放到页面上就可以显示图片）
								String path =imgPath + name + "." + extension;
								//图片上传的绝对路径
								File dir = new File(path);
								if (!dir.exists()) {
									dir.mkdirs();
								}
								// 上传图片
								pic.transferTo(new File(path));
								//							if(StringUtils.isNotBlank(fileName)) {
								//								q.setVideo(user.getId()+"/"+fileName);
								//								String delfile=filePath+courses.getVideo();
								//								File delvidel = new File(delfile);
								//								// 路径为文件且不为空则进行删除  
								//								if (delvidel.isFile() && delvidel.exists()) {  
								//									delvidel.delete();  
								//								}
								//								PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
								//							}
								//							PictureUtil.copyFile(fileTemPath+user.getId()+"/"+fileName, filePath+user.getId()+"/"+fileName);
								//							File source = new File(filePath+user.getId()+"/"+fileName);
								//							Encoder encoder = new Encoder();
								//							String length = "";
								//							MultimediaInfo m = encoder.getInfo(source);
								//							System.out.println("-------"+m.getDuration());
								//							long ls = m.getDuration()/1000;
								//							int hour = (int) (ls/3600);
								//							int minute = (int) (ls/60);
								//							int second = (int) (ls-hour*3600-minute*60);
								//							length = minute+":"+second;
								//							q.setViewTime(length);
								q.setCover(name + "." + extension);
								ServiceResultDto ts= coursesSeriesService.findpmodify(q);
								if(ts.getSuccess()) {
									OperationLog operationLog=new OperationLog();
									operationLog.setOperationType(3);
									operationLog.setOperationDescription("课程修改!");
									operationLog.setUserId(user);
									operationLog.setOperationTime(new Date());
									operationLog.setOperationUserName(user.getUserName());
									operationLogService.save(operationLog);
									resMap.put("code", "200");
									resMap.put("message","成功!");
									return JSONObject.fromObject(resMap).toString();
								}
							}
						}
					}else {

					}
					//				
				}else {
					resMap.put("code", "406");
					resMap.put("message", "请先登录!");
					return net.sf.json.JSONObject.fromObject(resMap).toString();
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			resMap.put("code", "500");
			resMap.put("message","系统异常");
			return JSONObject.fromObject(resMap).toString();
		}
		resMap.put("code", "500");
		resMap.put("message","操作异常!");
		return JSONObject.fromObject(resMap).toString();
	}
	/**
	 * 发布系列课
	 * @param token
	 * @param id
	 * @return
	 */
	@RequestMapping("/modifyReleaseStatus")
	@ResponseBody
	public String modifyReleaseStatus(@RequestParam(value="token", required=true) String token,String id) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					user.setUserPassword("");
					if(user.getIsRole()==4) {
						resMap.put("code", "500");
						resMap.put("message", "最高管理员不能操作!");
						return JSONObject.fromObject(resMap).toString();
					}
					CoursesSeriesQo coursesSeriesQo=new CoursesSeriesQo();
					coursesSeriesQo.setCoursesSeriesId(Long.parseLong(id));
					coursesSeriesQo.setSeachTeacher(true);
					CoursesSeries coursesSeries= coursesSeriesService.queryUnique(coursesSeriesQo);
					coursesSeries.setIsRelease(2);
					coursesSeriesService.update(coursesSeries);
					resMap.put("code", "200");
					resMap.put("message","发布成功!");
					return JSONObject.fromObject(resMap).toString();
				}
			}
			resMap.put("code", "500");
			resMap.put("message","系统异常");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message","异常抛出!");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 修改系列课子课程
	 * @param token
	 * @param id
	 * @param isPay
	 * @param courseTitle
	 * @return
	 */
	@RequestMapping("/modifySubSeries")
	@ResponseBody
	private String modifySubSeries(@RequestParam(value="token", required=true) String token,String id,Integer isPay,String courseTitle) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession!=null) {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user!=null) {
					user.setUserPassword("");
					if(user.getIsRole()==4) {
						resMap.put("code", "500");
						resMap.put("message", "最高管理员不能操作!");
						return JSONObject.fromObject(resMap).toString();
					}
					CoursesQo coursesQo=new CoursesQo();
					coursesQo.setSeachUploader(true);
					coursesQo.setSeachCoursesSeries(true);
					coursesQo.setCoursesId(Long.parseLong(id));
					Courses courses=coursesService.queryUnique(coursesQo);
					courses.setCoursetitle(courseTitle);
					courses.setIsPay(isPay);
					coursesService.update(courses);
					resMap.put("code", "200");
					resMap.put("message","修改成功!");
					return JSONObject.fromObject(resMap).toString();
				}
			}
			resMap.put("code", "500");
			resMap.put("message","请先登录!");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message","异常抛出!");
			return JSONObject.fromObject(resMap).toString();
		}
	}
}
